package org.hit.burkun.network;

import java.io.Serializable;
import java.util.HashSet;

import org.apache.commons.lang3.StringUtils;

/**
 * 顶点包，包括了唯一标识的umls和对应的在图中的id
 * @author burkun
 *
 */
public class Vertex implements Serializable{
	
	/**
	 * 顶点序列化
	 */
	private static final long serialVersionUID = -3315277303633180633L;
	private int uid = getNextCounter();
	private String umlsId = new String();
	private HashSet<String> dbids = new HashSet<>(); //hp do
	private HashSet<String> nodeType = new HashSet<>(); //evidence
	
	public String getNodeType() {
		return StringUtils.join(nodeType, ",");
	}
	
	
	public boolean isInNodeTypes(String type){
		return nodeType.contains(type);
	}

	public void setNodeType(String nodeTypee) {
		String[] res = nodeTypee.split(",");
		for(String nodet : res){
			this.nodeType.add(nodet);
		}
	}

	public int getUid() {
		return uid;
	}
	
	public String getUmlsId() {
		return umlsId;
	}
	public void setUmlsId(String umlsId) {
		this.umlsId = umlsId;
	}

	public void addDbId(String dbid) {
		dbids.add(dbid);
	}
	
	public String getDbids(){
		return StringUtils.join(dbids, ",");
	}
	
	private static int incCounter = 0;
	public static int getNextCounter(){
		return incCounter++;
	}
	public static void initNextCounter(){
		incCounter = 0;
	}
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Vertex){
			Vertex oo = (Vertex) obj;
			return oo.getUid() == uid;
		}
		return false;
	}
	
	@Override
	public String toString() {
		return this.umlsId +"|"+ getDbids();
	}
}
